package com.zhuss.timer;

import java.time.LocalDateTime;
import java.util.Calendar;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zhuss.core.db.dao.ext.DataDao;
import com.zhuss.util.JsonUtil;

/**
 * sql server 数据库数据 备份
 * 删除数据备份， 保留最近8天的备份
 * @author Administrator
 *
 */

@Component
@Configuration  
@EnableScheduling
public class DeleteData1000WTask {
	
	private static Logger  LOGGER = LoggerFactory.getLogger(DeleteData1000WTask.class);
	
	@Autowired
	private DataDao dataDao;
	
//	@Scheduled(cron = "0/20 * * * * ?")
	@Scheduled(cron = "3 3 3 * * ?")
	private void configureTasks() {
		Calendar cal = initCalendar();
		int influence = dataDao.delete1000W(cal.getTime());
		System.err.println("influence: " + JsonUtil.toJson(influence));
		System.err.println("DeleteData1000WTask-------执行静态定时任务时间: " + LocalDateTime.now());
	}
	
	private static Calendar initCalendar() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_YEAR, -8);
		cal.set(Calendar.HOUR_OF_DAY, 6);
		cal.set(Calendar.MINUTE, 53);
		cal.set(Calendar.SECOND, 12);
		System.out.println(cal.getTime());
		return cal;
	}

	public static void main(String[] args) {
		initCalendar();
	}
	
	
	public void execute(String cmd) {
		Process obj = null;
         try {
        	Thread.sleep(1000);
            obj = Runtime.getRuntime().exec(cmd);
            int status = obj.waitFor();
            LOGGER.error("status: " + status);
            // LOGGER.error(JsonUtil.toJson(obj));
         } catch (Exception e) {
        	e.printStackTrace();
        	//LOGGER.error(JsonUtil.toJson(obj));
         }
	}

}
